<?php
namespace App\Http\Controllers\Login;
use App\Http\Controllers\ApiBaseController;
use Illuminate\Http\Request;
use App\Models\AdminModels\AdminAction;
class AdminActionAjaxController extends ApiBaseController {

  public function __construct(Request $request) {
    parent::__construct($request);
  }

  /**
   * 列表
   * ajax数据
   */
  public function dataList(){
    $oAdminAction = new AdminAction();
    $result = $oAdminAction->getPageData($this->params);
    echo json_encode($result);
  }
  
  /**
   * 操作状态
   * 开启/关闭/删除
   */
  public function deleteData(){
    if(isset($this->params['id']) && intval($this->params['id']) > 0 && isset($this->params['status'])){
      $oAdminAction = new AdminAction();
      $result = $oAdminAction->db_get(['admin_action_id'=>['=',$this->params['id']]]);
      if(!empty($result)){
        if($oAdminAction->db_update('',$this->params['id'],['status'=>$this->params['status']])){
          \App\Components\Tools::adminLimits(true);
          \App\Components\Tools::newAdminLimits(true);
          $this->data = true;
        }else{
          $this->code = 1;
          $this->msg = '操作失败';
        }
      }else{
        $this->code = 1;
        $this->msg = '数据不存在';
      }
    }else{
      $this->code = 1;
      $this->msg = '缺少数据';
    }
    $this->boot();
  }
}